#polyline方法实现多个坐标点路径连线
#20240613 edit by LNSFAIoT 曾绍庚
from folium import plugins
import folium
import math
import os

citys = [[46.653186, 131.16534199999998, '双鸭山市'],
       [45.7763, 131.01154499999998, '七台河市'],
       [45.300872, 130.975619, '鸡西市'],
       [46.805690000000006, 130.327359, '佳木斯市'],
       [47.356056, 130.30443300000002, '鹤岗市'],
       [44.6, 129.58, '牡丹江市'],
       [42.915743, 129.477376, '延边朝鲜族自治州'],
       [47.733318, 128.847546, '伊春市'],
       [50.251272, 127.53549, '黑河市'],
       [46.660032, 126.975357, '绥化市'],
       [45.75, 126.63, '哈尔滨市'],
       [43.87, 126.57, '吉林市'],
       [41.939627, 126.42963, '白山市'],
       [41.733816, 125.946606, '通化市'],
       [43.88, 125.35, '长春市'],
       [42.894055, 125.150425, '辽源市'],
       [46.58, 125.03, '大庆市'],
       [45.147403999999995, 124.83148200000001, '松原市'],    
       ]

def  print_trace():
    # m = folium.Map([32.04,118.78], zoom_start=15)  #中心区域的确定
    # m = folium.Map(location=(lonlat['x'],lonlat['y']),
    m = folium.Map([45.75, 126.63],
 #    tiles='http://map.geoq.cn/ArcGIS/rest/services/ChinaOnlineStreetGray/MapServer/tile/{z}/{y}/{x}',
#  tiles='http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}', 
 tiles= 'https://wprd01.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=7',
 #    tiles='http://webst02.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}', # 高德卫星图
 #    tiles='https://mt.google.com/vt/lyrs=s&x={x}&y={y}&z={z}', # google 卫星图
 #    tiles="OpenStreetMap",
 zoom_start=14,
 attr='彩色版',
 lyrs='h',
 control_scale=True) 
    location = citys  #输入坐标点（注意）folium包要求坐标形式以纬度在前，经度在后
 
    #定义一个空列表将
    use_location=[]
 
    for i in range(len(location)):
        
        position_atitu = [location[i][0], location[i][1]]
        
        use_location.append([location[i][0], location[i][1]])
        
        if i < len(location) - 1:
            
            dx = location[i + 1][0] - location[i][0]  # dx
            
            dy = location[i + 1][1] - location[i][1]  # dy
 
            angle1 = math.atan2(dx, dy)
 
            angle2 = -int(angle1 * 180 / math.pi)
 
            mid_location = [location[i][0]+dx/2,location[i][1]+dy/2]
 
 
            #三角形图形指示方向，由于rotation的角度是顺时针旋转，
            folium.Marker(position_atitu, popup='<i>维度:</i>'+str(location[i][0])+'<br><i>经度:</i>'+str(location[i][1])+'<br><i>city_name:</i>'+location[i][2]).add_to(m)
            
            folium.RegularPolygonMarker(mid_location, fill_color='black', number_of_sides=3, radius=5,
                                    rotation=angle2).add_to(m)
        else:
            folium.Marker(position_atitu, popup='<i>维度:</i>'+str(location[i][0])+'<br><i>经度:</i>'+str(location[i][1])+'<br><i>city_name:</i>'+location[i][2]).add_to(m)
 
 
 
    #polyline方法为将坐标用线段形式连接起来
    route = folium.PolyLine(
        
        use_location,    #将坐标点连接起来
        
        weight=3,  #线的大小为3
        
        color='blue',  #线的颜色为橙色
        
        opacity=0.5,    #线的透明度
    ).add_to(m)    #将这条线添加到刚才的区域m内
 
    m.save(os.path.join(r'D:\工作\zsg','citymap.html'))
    
print_trace()